package com.tgy.thread;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.TimeUnit;

/**
 * @Author: tgy
 * @Date: 12/2/20 2:43 PM
 */
public class CountDownLatchDemo {

    public static void main(String[] args) throws Exception {


        CountDownLatch countDownLatch = new CountDownLatch(5);
        new Thread(()->{

            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            countDownLatch.countDown();
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            countDownLatch.countDown();
            countDownLatch.countDown();
        },"t1").start();

        new Thread(()->{

            countDownLatch.countDown();
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            countDownLatch.countDown();
        },"t2").start();

        countDownLatch.await();

        System.out.println("111");
    }
}
